package easy;

public class _121_BestTimetoBuyandSellStock {
    public int maxProfit(int[] prices) {
        int mProfit = 0;
        int maxPos = 0,minPos = 0;
        for(int i=1;i<prices.length;i++){
            if(prices[i]<prices[minPos]){
                minPos = i;
                maxPos = i;
            }else if(prices[i]>prices[maxPos]){
                maxPos = i;
                int tempProfit = prices[maxPos] - prices[minPos];
                if(mProfit<tempProfit){
                    mProfit = tempProfit;
                }
            }
        }
        return mProfit;
    }
}
